var Cube = Cube || {};

(function() {
	
	Cube = {
		
		/**
		 * Current version
		 * 
		 * @property {String} 
		 */
		version: '0.0.1',
		
		/**
		 * Show debug log messages
		 * 
		 * @property {Boolean} 
		 */
		debug: false,
		
		/**
		 * Empty function
		 * 
		 * @property {Function} 
		 */
		emptyFn: function() {},
		
		/**
		 * Config
		 * 
		 * @property {Object} 
		 */
		config: {},
		
		/**
		 * Run Cube 
		 */
		run: function() {
			Cube.config = {
				paths: {
					Cube: Cube.getRoot()
				}
			};
		},
		
		getRoot: function() {
			var scripts = document.getElementsByTagName("head")[0].getElementsByTagName("script");
			var path = scripts[scripts.length-1].src;
			return path.substring(0, path.lastIndexOf('/') + 1);
		},
		
		setup: function(options) {
			if (typeof options !== "object") options = {};
			if (typeof options.module === "undefined") Cube.Logger.error("Could not setup module, no module name was provided");
			if (typeof options.cache === "undefined") options.cache = false;
			if (typeof options.onLaunch !== "function") options.onLaunch = Cube.emptyFn;
			
			Cube.config.paths[options.module] 	= Cube.getRoot();
			Cube.config.cache 					= options.cache; 
			
			options.onLaunch.call();
		}
	};
	
	Cube.run();
	
})();